<template>
    <div>
        <h3>科室显示</h3>
        <div>
            科室名称<input type="text" v-model="arr.Name" />

            <input type="button" value="查询" @click="Show" class="btn btn-info" />
        </div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">科室名称</td>
                    <td align="right">科室人数</td>
                    <td align="right">科室介绍</td>

                    <td align="right">操作</td>
                </tr>
                <tr v-for="item in brr.list" :key="item.keShiId">
                    <td align="right">{{ item.keShiName }}</td>
                    <td align="right">{{ item.keShiNum }}</td>
                    <td align="right">{{ item.keShiJieShao }}</td>

                    <td align="right"><input type="button" value="编辑" @click="Up(item.keShiId)" class="btn btn-info" />
                        <input type="button" value="删除" @click="Del(item.keShiId)" class="btn btn-info" />
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

let arr: any = ref({
    Name: ""
})
let brr: any = ref({
    "list": []
})
onMounted(() => {
    Show();
})
const Show = () => {
    axios({
        url: "https://localhost:7107/api/Doctor/KeShiShow",
        params: arr.value,
        method: "get"
    })
        .then(res => {
            brr.value.list = res.data;
            console.log(brr.value.list);

        })
}



let use = useRouter();


const Up = (id: any) => {
    use.push({
        path: "/KeShiUp",
        query: { id: id }
    })
}


const Del = (id: any) => {
    let a = confirm('确认删除么？')
    if (a) {


        axios({
            url: "https://localhost:7107/api/Doctor/KeshiDel",
            params: { id: id },
            method: "delete"
        })
            .then(res => {
                if (res.data > 0) {
                    alert('删除成功');
                    Show();
                }
                else {
                    alert('删除失败');
                }
            })
    }
}

</script>

<style scoped>
span {
    padding: 15px 15px;
}
</style>